Skip to content

fix: make save_init_options() write atomically - #3924

Open
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/init-options-atomic-write
Open

fix: make save_init_options() write atomically#3924
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/init-options-atomic-write

Conversation

@Quratulain-bilal

Copy link
Copy Markdown
Contributor

Problem

write_text() directly to the target file risks leaving a partially written (corrupted) file if the process is killed mid-write.

Fix

Use mkstemp + os.replace for atomic write.

…n crash

write_text() directly to the target file risks leaving a partially
written (corrupted) file if the process is killed mid-write. Use
mkstemp + os.replace for atomic write.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Makes init-options persistence atomic to prevent partial writes.

Changes:

  • Writes JSON to a same-directory temporary file.
  • Atomically replaces the destination and cleans up on failure.
Show a summary per file
File Description
src/specify_cli/_init_options.py Implements atomic init-options writes.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +33 to +37
try:
with os.fdopen(fd, "w", encoding="utf-8") as f:
json.dump(options, f, indent=2, sort_keys=True, ensure_ascii=False)
f.write("\n")
os.replace(tmp, dest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants